package com.yinhe.music.yhmusic.video;

import android.util.Log;

import com.yinhe.music.yhmusic.base.IBaseModel;
import com.yinhe.music.yhmusic.network.response.ResponseTransformer;
import com.yinhe.music.yhmusic.share.SharePresenter;


/**
 * {@link VideoPlayingActivity} P层
 *
 * @author 何晓华
 */
public class VideoPlayingPresenter extends SharePresenter<IBaseModel, IVideoPlayingContract.IVideoPlayingView>
        implements IVideoPlayingContract.IVideoPlayingPresenter {

    @Override
    public void like(int mvId, int likeStatues) {
        if (getView() == null) {
            return;
        }

        if (likeStatues == 0) {
            addSubscription(mModel.mvLike(mvId)
                .compose(ResponseTransformer.handleResult())
                .compose(schedulerProvider.applySchedulers())
                .subscribe(baseInfo -> {}, throwable -> {
                    getView().afterLikeUI(true);
                    getView().showMessage(throwable);
                }));
        } else {
            addSubscription(mModel.mvUnLike(mvId)
                .compose(ResponseTransformer.handleResult())
                .compose(schedulerProvider.applySchedulers())
                .subscribe(baseInfo -> {}, throwable -> {
                    getView().afterLikeUI(false);
                    getView().showMessage(throwable);
                }));
        }
    }

    @Override
    public void collect(int mvId, int collectStatues) {
        if (getView() == null) {
            return;
        }

        getView().showLoading();
        if (collectStatues == 0) {
            addSubscription(mModel.collect(mvId, "movie")
                .compose(ResponseTransformer.handleResult())
                .compose(schedulerProvider.applySchedulers())
                .subscribe(baseInfo -> {
                    getView().hideLoading();
                }, throwable -> {
                    getView().afterCollectUI(true);
                    getView().showMessage(throwable);
                    getView().hideLoading();
                }));
        } else {
            addSubscription(mModel.unCollect(mvId, "movie")
                .compose(ResponseTransformer.handleResult())
                .compose(schedulerProvider.applySchedulers())
                .subscribe(baseInfo -> {
                    getView().hideLoading();
                }, throwable -> {
                    getView().afterCollectUI(false);
                    getView().showMessage(throwable);
                    getView().hideLoading();
                }));
        }
    }
}
